var MetroStyleDrawer = function (isStartingFlowHorizontal, galaxySpacing) {

    hDUnivSim_JsUtils.IncludeCssReference("css/styles_metro.css");

    var base = new InPageHtmlFixtureDrawer();
    var self = this;
    var _galaxySpacing = galaxySpacing == null ? 50 : galaxySpacing;
    var _isStartingFlowHorizontal = isStartingFlowHorizontal == null ? true : isStartingFlowHorizontal;

    $.extend(this, base);

    this.AnimationUtility = new MetroStyleAnimation();

    /*Helper Methods*/
    var GenerateCssForLiveTile = function (universeEntity) {

        var sizeAndPosition = universeEntity.SizeAndPosition;

        var cssMapObject = {
            'width': sizeAndPosition.Size.Width + 'px'
            , 'height': sizeAndPosition.Size.Height + 'px'
            , 'left': universeEntity.MetroStyleOptions_IsFlowHorizontal ? sizeAndPosition.Position.X : 0 + 'px'
            , 'top': !universeEntity.MetroStyleOptions_IsFlowHorizontal ? sizeAndPosition.Position.Y : 0 + 'px'
            , 'margin': '0px'
            , 'position': 'absolute'
        };

        return cssMapObject;
    };

    var GenerateLiveTileBase = function (universeEntity) {
        var jqObject = $('<div class="hdUnivLiveTile"></div>');

        jqObject.css(GenerateCssForLiveTile(universeEntity));

        return jqObject;
    };



    this.Draw = function (universeEntity) {

        var previousEntity = universeEntity.PreviousEntity();
        var parentEntity = universeEntity.ParentEntity();

        universeEntity.MetroStyleOptions_Spacing = universeEntity.UniverseEntityType >= UniverseEntityTypes.Galaxy ? _galaxySpacing : 0;

        if (universeEntity.UniverseEntityType >= UniverseEntityTypes.Galaxy || parentEntity == null || parentEntity.MetroStyleOptions_IsFlowHorizontal == null) {
            universeEntity.MetroStyleOptions_IsFlowHorizontal = _isStartingFlowHorizontal;
        }
        else {
            universeEntity.MetroStyleOptions_IsFlowHorizontal = !parentEntity.MetroStyleOptions_IsFlowHorizontal;
        }
        
        if (universeEntity.MetroStyleOptions_IsFlowHorizontal) {
            
            universeEntity.SizeAndPosition.Position.X = universeEntity.MetroStyleOptions_Spacing;

            if (parentEntity != null) {
                universeEntity.SizeAndPosition.Size.Height = parentEntity.SizeAndPosition.Size.Height;
                if (universeEntity.UniverseEntityType < UniverseEntityTypes.Galaxy)
                    universeEntity.SizeAndPosition.Size.Width = parentEntity.Children().length == 0 ? parentEntity.SizeAndPosition.Size.Width : parentEntity.SizeAndPosition.Size.Width / parentEntity.Children().length;
            }
            if (previousEntity != null) {
                universeEntity.SizeAndPosition.Position.X = previousEntity.SizeAndPosition.Position.X + previousEntity.SizeAndPosition.Size.Width + universeEntity.MetroStyleOptions_Spacing;
            }
        }
        else {

            universeEntity.SizeAndPosition.Position.Y = universeEntity.MetroStyleOptions_Spacing;

            if (parentEntity != null) {
                universeEntity.SizeAndPosition.Size.Width = parentEntity.SizeAndPosition.Size.Width;
                if (universeEntity.UniverseEntityType < UniverseEntityTypes.Galaxy)
                    universeEntity.SizeAndPosition.Size.Height = parentEntity.Children().length == 0 ? parentEntity.SizeAndPosition.Size.Height : parentEntity.SizeAndPosition.Size.Height / parentEntity.Children().length;
            }
            if (previousEntity != null) {
                universeEntity.SizeAndPosition.Position.Y = previousEntity.SizeAndPosition.Position.Y + previousEntity.SizeAndPosition.Size.Height + universeEntity.MetroStyleOptions_Spacing;
            }
        }

        var jqObject = base.Draw(universeEntity);
        jqObject.css(GenerateCssForLiveTile(universeEntity));

        //jqObject.append(GenerateLiveTileBase(universeEntity));

        return jqObject;
    };

};